package heven.holt.eyepetizer.fragment

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.google.android.material.tabs.TabLayoutMediator
import dagger.hilt.android.AndroidEntryPoint
import heven.holt.eyepetizer.R
import heven.holt.eyepetizer.databinding.EyeFragmentHomeBinding
import heven.holt.eyepetizer.loading.delegate.EyeHomeHeaderViewDelegate
import heven.holt.library.adapter.CommonViewPagerAdapter
import heven.holt.library.base.BaseLazyFragment
import heven.holt.library.loading.extensions.setLoadingStateCommonDecorHeader
import javax.inject.Inject

@AndroidEntryPoint
class EyeHomeFragment : BaseLazyFragment<EyeFragmentHomeBinding>() {
    @Inject
    lateinit var homeHeaderViewDelegate: EyeHomeHeaderViewDelegate

    private val tabNames by lazy {
        arrayOf(
            getString(R.string.discovery),
            getString(R.string.commend),
            getString(R.string.daily)
        )
    }

    override fun createDecorationView(): View {
        val loadingStateView =
            binding.root.setLoadingStateCommonDecorHeader(homeHeaderViewDelegate)
        return loadingStateView.decorView
    }

    override fun bindViewBinding(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): EyeFragmentHomeBinding =
        EyeFragmentHomeBinding.inflate(inflater, container, false)

    override fun initView() {
        val tabLayout = homeHeaderViewDelegate.binding.tabLayout
        val fragments = listOf(OtherFragment(), EyeCommendFragment(), OtherFragment())
        binding.viewPager.adapter = CommonViewPagerAdapter(this, fragments)
        TabLayoutMediator(tabLayout, binding.viewPager) { tab, position ->
            tab.text = tabNames[position]
        }.attach()
        binding.viewPager.setCurrentItem(1, false)
    }

    override fun initData() {
    }
}